/*
 * 作者:熊猫
 * 日期:2017 - 3 - 19 9 - 42 - 34
 *
 */

package net.lainiao.morethread.Chapter7.demo8;

import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2017/3/19.
 */
public class Task implements Runnable {
    private MyLock myLock;
    private String name;

    public Task(String name, MyLock myLock) {
        this.myLock = myLock;
        this.name = name;
    }

    @Override
    public void run() {
        myLock.lock();
        System.out.println("Task "+name+" is Lock");
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            System.out.println("Task "+name+" is Free");
            myLock.unlock();
        }
    }
}
